package com.itany.corejava.code07_常用类.日期类;

import java.util.Date;

/**
 * @author MissChen
 * @date 2024年03月01日 15:00
 */
public class Test02_常用方法 {
    public static void main(String[] args) {
        Date date=new Date();

        // 获取距离1970年1月1日0时0分0秒的毫秒数
        System.out.println(date.getTime());
        Date date2=new Date(date.getTime());
        System.out.println(date2);

        date2.setTime(0);
        System.out.println(date2);

        //将日期设置为前一天
        long time=date.getTime()-(24*60*60*1000);
        Date yestoday1=new Date();
        yestoday1.setTime(time);
        System.out.println(yestoday1);

        System.out.println("date是否在date3之后:"+date.after(yestoday1));
        System.out.println("date是否在date3之前:"+date.before(yestoday1));

        Date yestoday2=new Date(date.getTime()-(24*60*60*1000));
        System.out.println(yestoday2);
        System.out.println(date.compareTo(yestoday1));//1
        System.out.println(yestoday1.compareTo(yestoday2));//0
        System.out.println(yestoday2.compareTo(date));//-1


    }
}
